using UnityEngine;
using System.Collections;


[RequireComponent(typeof(GUITexture))]
public class ClickAble : MonoBehaviour
{

    public delegate void ExecuteDelegate(object argument = null);

    public ExecuteDelegate Execute;
    public object arguments;


    public Texture Hover;
    public Texture Active;

    public ActionType Action;

    public enum ActionType
    {
        Play = 0,
        Exit = 1,
        Restart = 2,
        RotateRight = 3,
        RotateLeft = 4,
        RotateUp = 5,
        RotateDown = 6,
        ChangeMovementSideWaysOnly = 7,
        ChangeMovementAllways = 8,
        ToggleInGameMenu = 9
    };
    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    void OnMouseDown()
    {
        this.guiTexture.texture = this.Active;
        this.ButtonClicked();
    }

    private void ButtonClicked()
    {
        switch (this.Action)
        {
            case ActionType.Play:
                Application.LoadLevel(1);
                break;
            case ActionType.Exit:
                Application.Quit();
                break;
            case ActionType.Restart:
                Application.LoadLevel(Application.loadedLevel);
                break;
            case ActionType.RotateRight:
                Rotator.Instance.RotateView(Rotator.RotateSide.Right);
                break;
            case ActionType.RotateUp:
                Rotator.Instance.RotateView(Rotator.RotateSide.Up);
                break;
            case ActionType.RotateDown:
                Rotator.Instance.RotateView(Rotator.RotateSide.Down);
                break;
            case ActionType.RotateLeft:
                Rotator.Instance.RotateView(Rotator.RotateSide.Left);
                break;
            case ActionType.ChangeMovementSideWaysOnly:
                Player.GetInstance().Movement.SideWaysOnly = true;
                this.GetComponent<GUITexture>().texture = this.Active;
                Debug.Log(this.guiTexture.texture);
                this.Action = ActionType.ChangeMovementAllways;
                break;
            case ActionType.ChangeMovementAllways:
                Player.GetInstance().Movement.SideWaysOnly = false;
                this.GetComponent<GUITexture>().texture = this.Hover;
                Debug.Log(this.guiTexture.texture);
                this.Action = ActionType.ChangeMovementSideWaysOnly;
                break;
            case ActionType.ToggleInGameMenu:
                Debug.Log("hi");
                GameLogic.Instance.InGameMenu.SetActive(!GameLogic.Instance.InGameMenu.activeSelf);

                break;
            default:
                break;
        }
    }
}

